

<!DOCTYPE html>
<html class="writer-html5" lang="en" >
<head>
  <meta charset="utf-8" />
  
  <meta name="viewport" content="width=device-width, initial-scale=1.0" />
  
  <title>CephFS 快照 &mdash; Ceph Documentation</title>
  

  
  <link rel="stylesheet" href="../../_static/ceph.css" type="text/css" />
  <link rel="stylesheet" href="../../_static/pygments.css" type="text/css" />
  <link rel="stylesheet" href="../../_static/graphviz.css" type="text/css" />
  <link rel="stylesheet" href="../../_static/css/custom.css" type="text/css" />

  
  
    <link rel="shortcut icon" href="../../_static/favicon.ico"/>
  

  
  

  

  
  <!--[if lt IE 9]>
    <script src="../../_static/js/html5shiv.min.js"></script>
  <![endif]-->
  
    
      <script type="text/javascript" id="documentation_options" data-url_root="../../" src="../../_static/documentation_options.js"></script>
        <script src="../../_static/jquery.js"></script>
        <script src="../../_static/underscore.js"></script>
        <script src="../../_static/doctools.js"></script>
    
    <script type="text/javascript" src="../../_static/js/theme.js"></script>

    
    <link rel="index" title="Index" href="../../genindex/" />
    <link rel="search" title="Search" href="../../search/" />
    <link rel="next" title="Cephx" href="../cephx/" />
    <link rel="prev" title="CephFS Reclaim Interface" href="../cephfs-reclaim/" /> 
</head>

<body class="wy-body-for-nav">

   
  <header class="top-bar">
    

















<div role="navigation" aria-label="breadcrumbs navigation">

  <ul class="wy-breadcrumbs">
    
      <li><a href="../../" class="icon icon-home"></a> &raquo;</li>
        
          <li><a href="../internals/">Ceph 内幕</a> &raquo;</li>
        
      <li>CephFS 快照</li>
    
    
      <li class="wy-breadcrumbs-aside">
        
          
            <a href="../../_sources/dev/cephfs-snapshots.rst.txt" rel="nofollow"> View page source</a>
          
        
      </li>
    
  </ul>

  
  <hr/>
</div>
  </header>
  <div class="wy-grid-for-nav">
    
    <nav data-toggle="wy-nav-shift" class="wy-nav-side">
      <div class="wy-side-scroll">
        <div class="wy-side-nav-search"  style="background: #eee" >
          

          
            <a href="../../">
          

          
            
            <img src="../../_static/logo.png" class="logo" alt="Logo"/>
          
          </a>

          

          
<div role="search">
  <form id="rtd-search-form" class="wy-form" action="../../search/" method="get">
    <input type="text" name="q" placeholder="Search docs" />
    <input type="hidden" name="check_keywords" value="yes" />
    <input type="hidden" name="area" value="default" />
  </form>
</div>

          
        </div>

        
        <div class="wy-menu wy-menu-vertical" data-spy="affix" role="navigation" aria-label="main navigation">
          
            
            
              
            
            
              <ul class="current">
<li class="toctree-l1"><a class="reference internal" href="../../start/intro/">Ceph 简介</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../install/">安装 Ceph</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../cephadm/">Cephadm</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../rados/">Ceph 存储集群</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../cephfs/">Ceph 文件系统</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../rbd/">Ceph 块设备</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../radosgw/">Ceph 对象网关</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../mgr/">Ceph 管理器守护进程</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../mgr/dashboard/">Ceph 仪表盘</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../api/">API 文档</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../architecture/">体系结构</a></li>
<li class="toctree-l1"><a class="reference internal" href="../developer_guide/">开发者指南</a></li>
<li class="toctree-l1 current"><a class="reference internal" href="../internals/">Ceph 内幕</a><ul class="current">
<li class="toctree-l2"><a class="reference internal" href="../blkin/">Tracing Ceph With LTTng</a></li>
<li class="toctree-l2"><a class="reference internal" href="../blkin/#tracing-ceph-with-blkin">Tracing Ceph With Blkin</a></li>
<li class="toctree-l2"><a class="reference internal" href="../bluestore/">BlueStore Internals</a></li>
<li class="toctree-l2"><a class="reference internal" href="../cache-pool/">Cache pool</a></li>
<li class="toctree-l2"><a class="reference internal" href="../ceph_krb_auth/">如何配置好 Ceph Kerberos 认证的详细文档</a></li>
<li class="toctree-l2"><a class="reference internal" href="../cephfs-mirroring/">CephFS Mirroring</a></li>
<li class="toctree-l2"><a class="reference internal" href="../cephfs-reclaim/">CephFS Reclaim Interface</a></li>
<li class="toctree-l2 current"><a class="current reference internal" href="#">CephFS 快照</a><ul>
<li class="toctree-l3"><a class="reference internal" href="#id1">概览</a></li>
<li class="toctree-l3"><a class="reference internal" href="#id2">重要的数据结构</a></li>
<li class="toctree-l3"><a class="reference internal" href="#id3">创建快照</a></li>
<li class="toctree-l3"><a class="reference internal" href="#id4">更新快照</a></li>
<li class="toctree-l3"><a class="reference internal" href="#snapcontext">生成 SnapContext</a></li>
<li class="toctree-l3"><a class="reference internal" href="#id5">存入快照数据</a></li>
<li class="toctree-l3"><a class="reference internal" href="#id6">存入快照元数据</a></li>
<li class="toctree-l3"><a class="reference internal" href="#id7">快照回写</a></li>
<li class="toctree-l3"><a class="reference internal" href="#id8">删除快照</a></li>
<li class="toctree-l3"><a class="reference internal" href="#id9">硬链接</a></li>
<li class="toctree-l3"><a class="reference internal" href="#id10">多文件系统情况</a></li>
</ul>
</li>
<li class="toctree-l2"><a class="reference internal" href="../cephx/">Cephx</a></li>
<li class="toctree-l2"><a class="reference internal" href="../cephx_protocol/">Cephx 认证协议详细阐述</a></li>
<li class="toctree-l2"><a class="reference internal" href="../config/">配置管理系统</a></li>
<li class="toctree-l2"><a class="reference internal" href="../config-key/">config-key layout</a></li>
<li class="toctree-l2"><a class="reference internal" href="../context/">CephContext</a></li>
<li class="toctree-l2"><a class="reference internal" href="../continuous-integration/">Continuous Integration Architecture</a></li>
<li class="toctree-l2"><a class="reference internal" href="../corpus/">资料库结构</a></li>
<li class="toctree-l2"><a class="reference internal" href="../cpu-profiler/">Oprofile 的安装</a></li>
<li class="toctree-l2"><a class="reference internal" href="../cxx/">C++17 and libstdc++ ABI</a></li>
<li class="toctree-l2"><a class="reference internal" href="../deduplication/">去重</a></li>
<li class="toctree-l2"><a class="reference internal" href="../delayed-delete/">CephFS delayed deletion</a></li>
<li class="toctree-l2"><a class="reference internal" href="../dev_cluster_deployement/">开发集群的部署</a></li>
<li class="toctree-l2"><a class="reference internal" href="../dev_cluster_deployement/#id5">在同一机器上部署多套开发集群</a></li>
<li class="toctree-l2"><a class="reference internal" href="../development-workflow/">开发流程</a></li>
<li class="toctree-l2"><a class="reference internal" href="../documenting/">为 Ceph 写作文档</a></li>
<li class="toctree-l2"><a class="reference internal" href="../encoding/">序列化（编码、解码）</a></li>
<li class="toctree-l2"><a class="reference internal" href="../erasure-coded-pool/">纠删码存储池</a></li>
<li class="toctree-l2"><a class="reference internal" href="../file-striping/">File striping</a></li>
<li class="toctree-l2"><a class="reference internal" href="../freebsd/">FreeBSD Implementation details</a></li>
<li class="toctree-l2"><a class="reference internal" href="../generatedocs/">Ceph 文档的构建</a></li>
<li class="toctree-l2"><a class="reference internal" href="../health-reports/">Health Reports</a></li>
<li class="toctree-l2"><a class="reference internal" href="../iana/">IANA 号</a></li>
<li class="toctree-l2"><a class="reference internal" href="../kubernetes/">Hacking on Ceph in Kubernetes with Rook</a></li>
<li class="toctree-l2"><a class="reference internal" href="../libs/">库体系结构</a></li>
<li class="toctree-l2"><a class="reference internal" href="../logging/">集群日志的用法</a></li>
<li class="toctree-l2"><a class="reference internal" href="../logs/">调试日志</a></li>
<li class="toctree-l2"><a class="reference internal" href="../macos/">在 MacOS 上构建</a></li>
<li class="toctree-l2"><a class="reference internal" href="../messenger/">Messenger notes</a></li>
<li class="toctree-l2"><a class="reference internal" href="../mon-bootstrap/">Monitor bootstrap</a></li>
<li class="toctree-l2"><a class="reference internal" href="../mon-elections/">Monitor Elections</a></li>
<li class="toctree-l2"><a class="reference internal" href="../mon-on-disk-formats/">ON-DISK FORMAT</a></li>
<li class="toctree-l2"><a class="reference internal" href="../mon-osdmap-prune/">FULL OSDMAP VERSION PRUNING</a></li>
<li class="toctree-l2"><a class="reference internal" href="../msgr2/">msgr2 协议（ msgr2.0 和 msgr2.1 ）</a></li>
<li class="toctree-l2"><a class="reference internal" href="../network-encoding/">Network Encoding</a></li>
<li class="toctree-l2"><a class="reference internal" href="../network-protocol/">网络协议</a></li>
<li class="toctree-l2"><a class="reference internal" href="../object-store/">对象存储架构概述</a></li>
<li class="toctree-l2"><a class="reference internal" href="../osd-class-path/">OSD class path issues</a></li>
<li class="toctree-l2"><a class="reference internal" href="../peering/">互联</a></li>
<li class="toctree-l2"><a class="reference internal" href="../perf/">Using perf</a></li>
<li class="toctree-l2"><a class="reference internal" href="../perf_counters/">性能计数器</a></li>
<li class="toctree-l2"><a class="reference internal" href="../perf_histograms/">Perf histograms</a></li>
<li class="toctree-l2"><a class="reference internal" href="../placement-group/">PG （归置组）说明</a></li>
<li class="toctree-l2"><a class="reference internal" href="../quick_guide/">开发者指南（快速）</a></li>
<li class="toctree-l2"><a class="reference internal" href="../rados-client-protocol/">RADOS 客户端协议</a></li>
<li class="toctree-l2"><a class="reference internal" href="../rbd-diff/">RBD 增量备份</a></li>
<li class="toctree-l2"><a class="reference internal" href="../rbd-export/">RBD Export &amp; Import</a></li>
<li class="toctree-l2"><a class="reference internal" href="../rbd-layering/">RBD Layering</a></li>
<li class="toctree-l2"><a class="reference internal" href="../release-checklists/">Release checklists</a></li>
<li class="toctree-l2"><a class="reference internal" href="../release-process/">Ceph Release Process</a></li>
<li class="toctree-l2"><a class="reference internal" href="../seastore/">SeaStore</a></li>
<li class="toctree-l2"><a class="reference internal" href="../sepia/">Sepia 社区测试实验室</a></li>
<li class="toctree-l2"><a class="reference internal" href="../session_authentication/">Session Authentication for the Cephx Protocol</a></li>
<li class="toctree-l2"><a class="reference internal" href="../testing/">测试笔记</a></li>
<li class="toctree-l2"><a class="reference internal" href="../versions/">Public OSD Version</a></li>
<li class="toctree-l2"><a class="reference internal" href="../vstart-ganesha/">NFS CephFS-RGW Developer Guide</a></li>
<li class="toctree-l2"><a class="reference internal" href="../wireshark/">Wireshark Dissector</a></li>
<li class="toctree-l2"><a class="reference internal" href="../zoned-storage/">Zoned Storage Support</a></li>
<li class="toctree-l2"><a class="reference internal" href="../osd_internals/">OSD 开发者文档</a></li>
<li class="toctree-l2"><a class="reference internal" href="../mds_internals/">MDS 开发者文档</a></li>
<li class="toctree-l2"><a class="reference internal" href="../radosgw/">RADOS 网关开发者文档</a></li>
<li class="toctree-l2"><a class="reference internal" href="../ceph-volume/">ceph-volume 开发者文档</a></li>
<li class="toctree-l2"><a class="reference internal" href="../crimson/">Crimson developer documentation</a></li>
</ul>
</li>
<li class="toctree-l1"><a class="reference internal" href="../../governance/">项目管理</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../foundation/">Ceph 基金会</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../ceph-volume/">ceph-volume</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../releases/general/">Ceph 版本（总目录）</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../releases/">Ceph 版本（索引）</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../security/">Security</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../glossary/">Ceph 术语</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../jaegertracing/">Tracing</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../translation_cn/">中文版翻译资源</a></li>
</ul>

            
          
        </div>
        
      </div>
    </nav>

    <section data-toggle="wy-nav-shift" class="wy-nav-content-wrap">

      
      <nav class="wy-nav-top" aria-label="top navigation">
        
          <i data-toggle="wy-nav-top" class="fa fa-bars"></i>
          <a href="../../">Ceph</a>
        
      </nav>


      <div class="wy-nav-content">
        
        <div class="rst-content">
        
          <div role="main" class="document" itemscope="itemscope" itemtype="http://schema.org/Article">
           <div itemprop="articleBody">
            
<div id="dev-warning" class="admonition note">
  <p class="first admonition-title">Notice</p>
  <p class="last">This document is for a development version of Ceph.</p>
</div>
  <div id="docubetter" align="right" style="padding: 5px; font-weight: bold;">
    <a href="https://pad.ceph.com/p/Report_Documentation_Bugs">Report a Documentation Bug</a>
  </div>

  
  <div class="section" id="cephfs">
<h1>CephFS 快照<a class="headerlink" href="#cephfs" title="Permalink to this headline">¶</a></h1>
<p>CephFS 支持快照，通常是在 <code class="docutils literal notranslate"><span class="pre">.snap</span></code> 目录下调用 mkdir 。注意，这是个隐藏的、特殊目录，罗列目录时不可见。</p>
<div class="section" id="id1">
<h2>概览<a class="headerlink" href="#id1" title="Permalink to this headline">¶</a></h2>
<p>通常，快照做的事正如其名：它们创建了一个拍下快照的那个时刻的文件系统视图。
有几个重要功能使得 CephFS 快照不同于你期望的样子：</p>
<ul class="simple">
<li><p>任意子树。快照可以在你选定的任何目录拍下，而且涵盖那个目录下的所有、
存在于文件系统上的数据。</p></li>
<li><p>异步性。如果你创建了一个快照，缓冲的数据是延后刷出的，包括其它客户端的数据。
因此，“创建”快照是非常迅速的。</p></li>
</ul>
</div>
<div class="section" id="id2">
<h2>重要的数据结构<a class="headerlink" href="#id2" title="Permalink to this headline">¶</a></h2>
<ul class="simple">
<li><p>SnapRealm: 只要你在目录层次内的新点上（或者，已经拍过快照的 inode
被移出了它的父级快照）创建了一个快照，就会创建 <cite>SnapRealm</cite> 。
SnapRealm 都包含一个 <cite>sr_t srnode</cite> 、和 <cite>inodes_with_caps</cite> ，都是快照的一部分。
客户端们也有一个 SnapRealm 概念，维护的数据较少，
但它是用于把 <cite>SnapContext</cite> 关联到各个打开、要写入的文件。</p></li>
<li><p>sr_t: <cite>sr_t</cite> 是磁盘上的快照元数据。它是所在目录的一部分，
包含顺序计数器、时间戳、关联的快照 ID 的列表、和 <cite>past_parent_snaps</cite> 。</p></li>
<li><p>SnapServer: SnapServer 管理着快照 ID 的分配、快照删除、
并追踪着文件系统内有效快照的各个列表。一个文件系统只有一个 snapserver 例程。</p></li>
<li><p>SnapClient: SnapClient 用于和 snapserver 通讯，
每个 MDS rank 都有它们自己的 snapclient 例程。
SnapClient 也会在本地缓存有效的快照。</p></li>
</ul>
</div>
<div class="section" id="id3">
<h2>创建快照<a class="headerlink" href="#id3" title="Permalink to this headline">¶</a></h2>
<p>CephFS 的快照功能在新文件系统上是默认启用的，要在现有文件系统上启用，
用以下命令。</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span>$ ceph fs set &lt;fs_name&gt; allow_new_snaps true
</pre></div>
</div>
<p>快照功能启用后， CephFS 内的所有目录都有一个特殊的 <code class="docutils literal notranslate"><span class="pre">.snap</span></code> 目录。
（你如果愿意，可以用 <code class="docutils literal notranslate"><span class="pre">client</span> <span class="pre">snapdir</span></code> 选项配置个不同的名字。）</p>
<p>要创建一个 CephFS 快照，在 <code class="docutils literal notranslate"><span class="pre">.snap</span></code> 下创建一个子目录就行，
名字随你。例如，要给 /1/2/3/ 目录创建一个快照，
可以用 <code class="docutils literal notranslate"><span class="pre">mkdir</span> <span class="pre">/1/2/3/.snap/my-snapshot-name</span></code> 。</p>
<p>这会作为一个用 CEPH_MDS_OP_MKSNAP 打了标签的 <cite>MClientRequest</cite> 传给 MDS 服务器，
起初在 Server::handle_client_mksnap() 里处理。它从 <cite>SnapServer</cite> 分到了一个 <cite>snapid</cite> ，用新的 SnapRealm 规划了一个新的 inode ，并像往常一样提交到 MDLog 。
提交后，它会调用 <cite>MDCache::do_realm_invalidate_and_update_notify()</cite> ，
就会通知所有客户端，内容是 /1/2/3/ 下的文件们多了一层帽子，就是新的 SnapRealm 。
客户端们收到通知后，它们会更新客户端这边的 SnapRealm 层次结构，
把 /1/2/3/ 下的文件连接到这个新的 SnapRealm 、
并为新的 SnapRealm 生成一个 <cite>SnapContext</cite> 。</p>
<p>注意，这 <em>不是</em> 快照创建过程中的同步部分。</p>
</div>
<div class="section" id="id4">
<h2>更新快照<a class="headerlink" href="#id4" title="Permalink to this headline">¶</a></h2>
<p>如果你删除一个快照，走的过程相似。如果你把一个 inode 挪出它的父级 SnapRealm ，
重命名代码会给重命名过的 inode 创建一个新的 SnapRealm （如果还没有 SnapRealm ），
把原来父级 SnapRealm 上有效快照们的 ID 保存到新 SnapRealm 的 <cite>past_parent_snaps</cite> 里，
然后再走一次与新建快照相似的流程。</p>
</div>
<div class="section" id="snapcontext">
<h2>生成 SnapContext<a class="headerlink" href="#snapcontext" title="Permalink to this headline">¶</a></h2>
<p>RADOS <cite>SnapContext</cite> 包括一个快照顺序 ID （ <cite>snapid</cite> ）、和这个对象牵涉的所有快照 ID 。
要生成这个列表，我们把 SnapRealm 关联的 <cite>snapids</cite> 、和 <cite>past_parent_snaps</cite> 里的所有 <cite>snapids</cite> 结合起来，过时的 <cite>snapids</cite> 会被 SnapClient 缓存的有效快照过滤出去。</p>
</div>
<div class="section" id="id5">
<h2>存入快照数据<a class="headerlink" href="#id5" title="Permalink to this headline">¶</a></h2>
<p>文件数据存储在 RADOS “自己管理的”快照中。客户端在向 OSD 们写入文件数据时会小心地使用正确的 <cite>SnapContext</cite> 。</p>
</div>
<div class="section" id="id6">
<h2>存入快照元数据<a class="headerlink" href="#id6" title="Permalink to this headline">¶</a></h2>
<p>拍过快照的 dentry （以及它们的 inode ）将作为目录的一部分以内联方式存储。
<em>所有的 dentry</em> 包含有 <cite>first</cite> 和 <cite>last</cite> snapid 的都是有效的。
（没拍过快照的 dentry 有 <cite>last</cite> 集合指向 CEPH_NOSNAP ）。</p>
</div>
<div class="section" id="id7">
<h2>快照回写<a class="headerlink" href="#id7" title="Permalink to this headline">¶</a></h2>
<p>有大量的代码可以有效地处理回写。客户端收到一条 <cite>MClientSnap</cite> 消息时，
它会更新本地 <cite>SnapRealm</cite> 表达式、以及它指向特定 <cite>Inodes</cite> 的连接，
并给这个 <cite>Inode</cite> 生成一个 <cite>CapSnap</cite> 。 <cite>CapSnap</cite> 会作为能力回写的一部分刷出去、
而且，如果存在脏数据， <cite>CapSnap</cite> 会阻塞新数据的写入，直到快照完全被刷回到 OSD 。</p>
<p>在 MDS 里，作为刷回的、常规流程的一部分，我们生成表示快照的 dentry 。
含有凸出的 <cite>CapSnap</cite> 数据的 dentry 会被保持在挂单状态、且在日志中。</p>
</div>
<div class="section" id="id8">
<h2>删除快照<a class="headerlink" href="#id8" title="Permalink to this headline">¶</a></h2>
<p>在目录的 .snaps 目录内调用 rmdir 就能删除快照。（试图删除有快照的目录 <em>会失败</em> ；
必须先删除所有快照。）一旦被删除，它们就进入 <cite>OSDMap</cite> 里的已删除快照列表、
之后文件数据就会被 OSD 删除。元数据会在目录对象被读入并再次写回时被清理掉。</p>
</div>
<div class="section" id="id9">
<h2>硬链接<a class="headerlink" href="#id9" title="Permalink to this headline">¶</a></h2>
<p>有多个硬链接的 inode 会被挪进一个虚拟的全局 SnapRealms ，这个虚拟 SnapRealms
统管文件系统内的所有快照。这个 inode 的数据会保留给所有新快照，
这些保留的数据会覆盖所有与此 inode 相关的快照内链接。</p>
</div>
<div class="section" id="id10">
<h2>多文件系统情况<a class="headerlink" href="#id10" title="Permalink to this headline">¶</a></h2>
<p>快照功能和多个文件系统还没有很好地对接。特别是，各个 MDS 集群是独立地分配 <cite>snapids</cite> 的；
如果你有多个文件系统共享着同一个存储池（通过命名空间），它们的快照会冲突、而且删除一个会导致另一个的文件数据丢失。（这甚至是不可见的，不会向用户抛出错误。）
如果各个 FS 都有它们自己的存储池，也许可以正常工作，但是这种场景还没完全测试，
有可能和期望的不一样。</p>
</div>
</div>



           </div>
           
          </div>
          <footer>
    <div class="rst-footer-buttons" role="navigation" aria-label="footer navigation">
        <a href="../cephx/" class="btn btn-neutral float-right" title="Cephx" accesskey="n" rel="next">Next <span class="fa fa-arrow-circle-right" aria-hidden="true"></span></a>
        <a href="../cephfs-reclaim/" class="btn btn-neutral float-left" title="CephFS Reclaim Interface" accesskey="p" rel="prev"><span class="fa fa-arrow-circle-left" aria-hidden="true"></span> Previous</a>
    </div>

  <hr/>

  <div role="contentinfo">
    <p>
        &#169; Copyright 2016, Ceph authors and contributors. Licensed under Creative Commons Attribution Share Alike 3.0 (CC-BY-SA-3.0).

    </p>
  </div> 

</footer>
        </div>
      </div>

    </section>

  </div>
  

  <script type="text/javascript">
      jQuery(function () {
          SphinxRtdTheme.Navigation.enable(true);
      });
  </script>

  
  
    
   

</body>
</html>